package com.genITeam.ria.actions;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.BasicConfigurator;
import org.apache.log4j.Logger;

import com.genITeam.ria.bl.LoginBL;
import com.genITeam.ria.exception.NGFException;
import com.genITeam.ria.vo.Member;

public class LoginAction extends AbstractAction {

	public LoginAction() {
		BasicConfigurator.configure();
	}

	Logger logger = Logger.getLogger(LoginAction.class);

	/**
	 * handleLoginVerification to get Parameters from Request object and write
	 * resulting response
	 * 
	 * 
	 * @param HttPServletRequest,HttpServletResponse
	 * @return none
	 * @throws NGFException
	 */

	public void handleLoginVerification(HttpServletRequest request,
			HttpServletResponse response) throws NGFException {
		LoginBL loginBL = new LoginBL();

		try {
			logger.info("Start handleLoginVerification");
			String userName = request.getParameter("userName");
			String password = request.getParameter("password");
			System.out.println("userName =" + userName);
			System.out.println("password =" + password);
			Member member = new Member();
			member.setUserName(userName);
			member.setPassword(password);
			this.initAction(request, response);
			this.writeResponse(loginBL.verifyLogin(member));

		} catch (NGFException e) {
			this.initAction(request, response);
			this.writeResponse("<error>" + e.getErrorMessage() + "</error>");
			System.out.print("Search Forum Excepton = "+ e.getMessage());
		} catch (Exception e) {
			logger.error("Exception=" + e.toString());
			this.initAction(request, response);
			this.writeResponse("<error>" + e.getMessage() + "</error>");
		}
	}
}
